package Tables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class Course extends Table{
    private int id;
    private String name;
    private double credits;
    private int hours;
    private String course_properties;
    public Course(Connection connection) {
        super(connection);
    }

    @Override
    public String toString() {
        return "Course{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", credits=" + credits +
                ", hours=" + hours +
                ", course_properties='" + course_properties + '\'' +
                '}';
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getCredits() {
        return credits;
    }

    public void setCredits(double credits) {
        this.credits = credits;
    }

    public int getHours() {
        return hours;
    }

    public void setHours(int hours) {
        this.hours = hours;
    }

    public String getCourse_properties() {
        return course_properties;
    }

    public void setCourse_properties(String course_properties) {
        this.course_properties = course_properties;
    }

    @Override
    public List<String> get() throws SQLException {
        String order = "select * from course";
        PreparedStatement statement = this.connection.prepareStatement(order);
        ResultSet set = statement.executeQuery();
        while(set.next()){
            this.id = set.getInt(1);
            this.name = set.getString(2);
            this.credits = set.getDouble(3);
            this.hours = set.getInt(4);
            this.course_properties = set.getString(5);
            this.tableList.add(toString());
        }
        return this.tableList;
    }
}
